//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "YYEUHICPXT.h"
using namespace Cephei::QL::Indexes::Inflation;
#include <gen/QL/Termstructures/YoYInflationTermStructure.h>
#include <gen/QL/Indexes/Region.h>
#include <gen/QL/Times/Period.h>
#include <gen/QL/Currency.h>
#include <gen/QL/Indexes/YoYInflationIndex.h>
#include <gen/QL/Times/Calendar.h>
using namespace Cephei::QL::Termstructures;
using namespace Cephei::QL::Indexes;
using namespace Cephei::QL::Times;
using namespace Cephei::QL;
#define HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Indexes::Inflation::CYYEUHICPXT::CYYEUHICPXT (Boolean interpolated, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYoYInflationTermStructure^>^ ts) : CYoYInflationIndex(CYYEUHICPXT::typeid)
{
    CYoYInflationTermStructure^ _Cts;
    try
    {
#ifdef HANDLE
        _phYYEUHICPXT = NULL;
#endif
        bool _interpolated = (bool)ValueHelper::Convert (interpolated); //d
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYoYInflationTermStructure^>::IsSome::get (ts))
        {
            _Cts = safe_cast<CYoYInflationTermStructure^> (ts->Value);
            _Cts->Lock();
        }
        Handle<QuantLib::YoYInflationTermStructure>& _ts = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYoYInflationTermStructure^>::IsSome::get (ts) ? static_cast<Handle<QuantLib::YoYInflationTermStructure>&> (_Cts->GetHandle ()) : Handle<QuantLib::YoYInflationTermStructure>()); //1
        _ppYYEUHICPXT = new boost::shared_ptr<QuantLib::YYEUHICPXT> (new QuantLib::YYEUHICPXT ( _interpolated,  _ts ));
        SetYoYInflationIndex (boost::dynamic_pointer_cast<QuantLib::YoYInflationIndex> (*_ppYYEUHICPXT));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cts != nullptr) _Cts->Unlock();
    }
}
Cephei::QL::Indexes::Inflation::CYYEUHICPXT::CYYEUHICPXT (boost::shared_ptr<QuantLib::YYEUHICPXT>& childNative, Object^ owner) : CYoYInflationIndex(CYYEUHICPXT::typeid)
{
#ifdef HANDLE
	_phYYEUHICPXT = NULL;
#endif
	_ppYYEUHICPXT = &childNative;
    _ppYoYInflationIndex = new boost::shared_ptr<QuantLib::YoYInflationIndex> (boost::dynamic_pointer_cast<QuantLib::YoYInflationIndex> (*_ppYYEUHICPXT));
}
Cephei::QL::Indexes::Inflation::CYYEUHICPXT::CYYEUHICPXT (QuantLib::YYEUHICPXT& childNative, Object^ owner) : CYoYInflationIndex(CYYEUHICPXT::typeid)
{
#ifdef HANDLE
	_phYYEUHICPXT = NULL;
#endif
	_ppYYEUHICPXT = new boost::shared_ptr<QuantLib::YYEUHICPXT> (&childNative);
    _ppYoYInflationIndex = new boost::shared_ptr<QuantLib::YoYInflationIndex> (boost::dynamic_pointer_cast<QuantLib::YoYInflationIndex> (*_ppYYEUHICPXT));
    _YYEUHICPXTOwner = owner;
    _YoYInflationIndexOwner = owner;
}

Cephei::QL::Indexes::Inflation::CYYEUHICPXT::CYYEUHICPXT (CYYEUHICPXT^ copy) : CYoYInflationIndex(CYYEUHICPXT::typeid)
{
#ifdef HANDLE
	_phYYEUHICPXT = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppYYEUHICPXT = new boost::shared_ptr<QuantLib::YYEUHICPXT> (copy->GetShared());
        _ppYoYInflationIndex = new boost::shared_ptr<QuantLib::YoYInflationIndex> (boost::dynamic_pointer_cast<QuantLib::YoYInflationIndex> (*_ppYYEUHICPXT));
    }
}
Cephei::QL::Indexes::Inflation::CYYEUHICPXT::CYYEUHICPXT (PLATFORM::Type^ t) : CYoYInflationIndex(CYYEUHICPXT::typeid)
{
#ifdef HANDLE
	_phYYEUHICPXT = NULL;
#endif
	if (!t->IsSubclassOf(CYYEUHICPXT::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Indexes::Inflation::CYYEUHICPXT::CYYEUHICPXT (QuantLib::Handle<QuantLib::YYEUHICPXT>& childNative, Object^ owner)  : CYoYInflationIndex(CYYEUHICPXT::typeid)
{
	_phYYEUHICPXT = &childNative;
	_ppYYEUHICPXT = &static_cast<boost::shared_ptr<QuantLib::YYEUHICPXT>>(childNative.currentLink());
    _ppYoYInflationIndex = new boost::shared_ptr<QuantLib::YoYInflationIndex> (boost::dynamic_pointer_cast<QuantLib::YoYInflationIndex> (*_ppYYEUHICPXT));
    _YYEUHICPXTOwner = owner;
}
Cephei::QL::Indexes::Inflation::CYYEUHICPXT::CYYEUHICPXT (QuantLib::Handle<QuantLib::YYEUHICPXT> childNative)  : CYoYInflationIndex(CYYEUHICPXT::typeid)
{
	_phYYEUHICPXT = &childNative;
	_ppYYEUHICPXT = &static_cast<boost::shared_ptr<QuantLib::YYEUHICPXT>>(childNative.currentLink());
    _ppYoYInflationIndex = new boost::shared_ptr<QuantLib::YoYInflationIndex> (boost::dynamic_pointer_cast<QuantLib::YoYInflationIndex> (*_ppYYEUHICPXT));
}
#endif
#ifdef STRUCT
Cephei::QL::Indexes::Inflation::CYYEUHICPXT::CYYEUHICPXT (QuantLib::YYEUHICPXT childNative)  : CYoYInflationIndex(CYYEUHICPXT::typeid)
{
#ifdef HANDLE
	_phYYEUHICPXT = NULL;
#endif
	_ppYYEUHICPXT = new boost::shared_ptr<QuantLib::YYEUHICPXT> (new QuantLib::YYEUHICPXT (childNative));
    _ppYoYInflationIndex = new boost::shared_ptr<QuantLib::YoYInflationIndex> (boost::dynamic_pointer_cast<QuantLib::YoYInflationIndex> (*_ppYYEUHICPXT));
}
#endif

Cephei::QL::Indexes::Inflation::CYYEUHICPXT::~CYYEUHICPXT ()
{
    if (_ppYYEUHICPXT != NULL)
    {
	    delete _ppYYEUHICPXT;
        _ppYYEUHICPXT = NULL;
    }
}
Cephei::QL::Indexes::Inflation::CYYEUHICPXT::!CYYEUHICPXT ()
{
    if (_ppYYEUHICPXT != NULL)
    {
	    delete _ppYYEUHICPXT;
    }
}
QuantLib::YYEUHICPXT& Cephei::QL::Indexes::Inflation::CYYEUHICPXT::GetReference ()
{
    if (_ppYYEUHICPXT == NULL) throw REFNEW NativeNullException ();
	return **_ppYYEUHICPXT;
}
boost::shared_ptr<QuantLib::YYEUHICPXT>& Cephei::QL::Indexes::Inflation::CYYEUHICPXT::GetShared ()
{
    if (_ppYYEUHICPXT == NULL) throw REFNEW NativeNullException ();
	return *_ppYYEUHICPXT;
}
QuantLib::YYEUHICPXT* Cephei::QL::Indexes::Inflation::CYYEUHICPXT::GetPointer ()
{
    if (_ppYYEUHICPXT == NULL) throw REFNEW NativeNullException ();
	return &**_ppYYEUHICPXT;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::YYEUHICPXT>& Cephei::QL::Indexes::Inflation::CYYEUHICPXT::GetHandle ()
{
	if (_phYYEUHICPXT == NULL)
	{
		_phYYEUHICPXT = new Handle<QuantLib::YYEUHICPXT> (*_ppYYEUHICPXT);
	}
	return *_phYYEUHICPXT;
}
#endif
bool Cephei::QL::Indexes::Inflation::CYYEUHICPXT::HasNative () 
{
	return (_ppYYEUHICPXT != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Indexes::Inflation::IYYEUHICPXT^ Cephei::QL::Indexes::Inflation::CYYEUHICPXT_Factory::Create (Boolean interpolated, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Termstructures::IYoYInflationTermStructure^>^ ts)
{
    return REFNEW CYYEUHICPXT ( interpolated,  ts);
}
